package 学生成绩查询管理系统.界面;

import 学生成绩查询管理系统.功能.*;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class StudentFrame extends JFrame implements ActionListener{
    private JMenuItem reLogin;
    private JMenuItem menu;
    private JMenuItem exit;
    private JMenuItem aboutMe;
    private JPanel root;
    JButton score;
    JButton classroom ;
    JButton course;
    JButton updatePasswordButton;
    private MyTray myTray; // 将MyTray对象设置为类成员变量
    private JLabel label1;
    String path="C:\\Users\\23513\\Desktop\\学生成绩管理系统\\";
    private DefaultTableModel tableModel;
    public StudentFrame(){
        initJframe();
        initMenu();
        this.setVisible(true);

    }

    private void initJframe(){


        this.setTitle("学生成绩查询管理系统");
        this.setSize(600,450);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Font centerFont=new Font("正楷",Font.PLAIN,15);
        Font FFont=new Font("华文行楷",Font.PLAIN,35);
        //添加标语
        label1= new JLabel("欢迎来到学生成绩查询管理系统", JLabel.CENTER);
        getContentPane().add(label1);
        label1.setBounds(40,100,500,200);

        label1.setFont(FFont);
        //添加按钮
        score = new JButton("成绩查询");
        classroom = new JButton("我的班级");

        updatePasswordButton = new JButton("修改密码");


        score.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                SwingUtilities.invokeLater(() -> {
                    StudentInquirey studentInquirey = new StudentInquirey();
                    studentInquirey.setVisible(true);
                });
                dispose();
            }
        });

        classroom.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                SwingUtilities.invokeLater(() -> {
                    StudentInquirey2 studentInquirey2 = new StudentInquirey2();
                    studentInquirey2.setVisible(true);
                });
            }
        });



        updatePasswordButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                StudentInquiry3 inquiryManager = new StudentInquiry3();
                inquiryManager.openUpdatePasswordDialog();
            }


        });


        score.setBackground(Color.CYAN);
        classroom.setBackground(Color.CYAN);

        updatePasswordButton.setBackground(Color.CYAN);

        score.setBounds(80,5,100,30);
        classroom.setBounds(80+150,5,100,30);
        updatePasswordButton.setBounds(80+300,5,100,30);
        Font centerFont1=new Font("宋体",Font.PLAIN,15);

        score.setOpaque(false);
        classroom.setOpaque(false);

        updatePasswordButton.setOpaque(false);

        score.setFont(centerFont1);
        classroom.setFont(centerFont1);

        updatePasswordButton.setFont(centerFont1);
        this.getContentPane().add(score);
        this.getContentPane(). add(classroom);

        this.getContentPane(). add(updatePasswordButton);



        // 修改图标
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image img = tk.getImage("imge\\成绩录入2.png");
        setIconImage(img);

        // 设置背景图片
        ImageIcon imageIcon = new ImageIcon("imge\\主界面2.png");
        JLabel label = new JLabel(imageIcon);
        getContentPane().add(label, BorderLayout.CENTER);
        setLocationRelativeTo(null);//居中显示
    }
    private void initMenu() {
        JMenuBar jMenuBar = new JMenuBar();
        JMenu about = new JMenu("关于我");
        JMenu function = new JMenu("功能");
        aboutMe = new JMenuItem("QQ二维码");
        reLogin = new JMenuItem("重新登录");
        menu = new JMenuItem("主页");
        exit = new JMenuItem("退出");

        about.add(aboutMe);
        function.add(reLogin);
        function.add(menu);
        function.add(exit);

        aboutMe.addActionListener(this);
        reLogin.addActionListener(this);
        menu.addActionListener(this);
        exit.addActionListener(this);

        jMenuBar.add(about);
        jMenuBar.add(function);
        this.setJMenuBar(jMenuBar);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 获取当前被点击的条目对象
        Object obj = e.getSource();
        if (obj == reLogin) {
            dispose();
            new Login();
        } else if (obj == menu) {
            dispose();
            new StudentFrame();
        } else if (obj == exit) {
            System.exit(0);
        } else if (obj == aboutMe) {
            // 创建一个弹框对象
            JDialog jDialog = new JDialog();
            Toolkit tk = Toolkit.getDefaultToolkit();
            Image img = tk.getImage("imge\\成绩录入2.png");
            jDialog.setIconImage(img);
            // 创建一个管理图片的容器对象JLabel
            JLabel jLabel = new JLabel(new ImageIcon("imge\\about.png"));
            // 设置位置和宽高
            jLabel.setBounds(0, 0, 300, 380);
            // 把图片添加到弹框当中
            jDialog.getContentPane().add(jLabel);
            // 给弹框设置大小
            jDialog.setSize(400, 400);
            // 让弹框置顶
            jDialog.setAlwaysOnTop(true);
            // 让弹框居中
            jDialog.setLocationRelativeTo(null);
            // 弹框不关闭则无法操作下面的界面
            jDialog.setModal(true);
            // 让弹框显示出来
            jDialog.setVisible(true);
        }

    }


    }


